{template header}
<script src="static/bootstrap/js/utils.js"></script>
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>
<script src="{$staticHost}js/ColorPicker.js"></script>
<style type="text/css">
   .pad5 {padding-top: 10px;}
   .pad-left10 {padding-left: 10px;}
   .label-in-control {float: left;padding-top: 5px;text-align: right;width: 50px;}
   .label-in-control input {width: 50px;}
   .control-in-controls {margin-left: 70px;padding-top: 5px;}
   .control-in-controls input {width: 500px;}
   .control-group .controls label{float:left; margin-right: 10px;}

 
</style>
<script type="text/javascript">
  $(document).ready(function(){
      $("button#addGearImg").click(function(){
            var num = $("#MaxGearImg").val();
            if(num == undefined)
                num = 0;
            num = parseInt(num);
            $("#MaxGearImg").val(num+1);
            var newHtml = "<div class='control-group gearImgDiv'><label class='control-label'>+装备图片：</label><div class='controls'><div class='control-group'><div class=''><input type='file' name='picture_"+num +"'></div></div></div><div class='controls'><button type='button' class='btn btn-danger' onclick='delGearImg(this)'>删除本图</button></div></div>";
            $(".AddGearImg-div").before(newHtml);
      });
      // 添加配色
      $("button#addBlendent").click(function(){
            var num = $("#Maxlendent").val();
            if(num == undefined)
                num = 0;
            num = parseInt(num);
            $("#Maxlendent").val(num+1);


            var newHtml = "<div class=\"control-group blendent\"><label class=\"control-label\">配色色值：</label><div class=\"controls\"><input type=\"text\" id=\"color0_" + num + "\" name=\"color_"+ num + "[]\" disabled=\"disabled\" placeholder=\"请选择色值\"><br /><input type=\"text\" id=\"color1_"+ num +"\" name=\"color_"+ num + "[]\" disabled=\"disabled\" placeholder=\"请选择色值\" ></div><label class=\"control-label\">图片：</label><div class=\"controls\"><input type=\"file\" name=\"blendent_"+ num +"\"></div><div class=\"controls\"><button type=\"button\" class=\"btn btn-danger\" onclick=\"delblendent(this,0)\">删除本配色</button></div></div>";

            $(".AddBlendent").before(newHtml);

            // 创建颜色选择器
            CreateCPBtn('color0_'+ num);
            CreateCPBtn('color1_'+ num);
      });
      // 添加评测
      $("button#addEvaluate").click(function(){
            var num = $("#MaxEval").val();
            if(num == undefined)
                num = 0;
            num = parseInt(num);
            $("#MaxEval").val(num+1);

            var newHtml = "<div class=\"control-group evaluate\"><label class=\"control-label\">+测评：</label><div class=\"controls\"><label class=\"label-in-control\">ID：</label><div class=\"control-in-controls\"><input type=\"text\" name=\"evaluate[]\" placeholder=\"帖子ID\" id=\"evaluateid\"></div><label class=\"label-in-control\">标题：</label><div class=\"control-in-controls evaluate-title\"><input type=\"text\" disabled=\"disabled\" ></div><label class=\"label-in-control\">图片：</label><div class=\"control-in-controls  evaluate-img\"></div></div><div class=\"controls pad5 pad-left10\"><button type=\"button\" class=\"btn btn-danger\" onclick=\"delEvaluate(this)\">删除本评测</button></div></div>";

            $(".AddEvaluate").before(newHtml);
      });
      // 获取评测信息
      $("input#evaluateid").blur(function(){
            var frm =$(this);
            var id = frm.val(); // 帖子id
            if(Utils.isEmpty(id))
            {
              alert('既然来了，就留个帖子id吧');
              return false;
            }

            $.ajax({url:"index.php?c=admin&a=getPostInfo&id=" + id,
                  async:false,
                  dataType:"json",
                  error:function(){
                      alert('未知错误');
                      },
                  success:function(data, status){
                    turnData = eval(data);
                    if(turnData.message == '') {
                        var imgHtml = '';
                        var title = turnData.data.t;
                        for(var i=0; i<turnData.data.img.length; i++)
                        {
                          imgHtml += "<img width=\"50\" src=\"" + turnData.data.img[i] + "\">";
                        }
                        updateEvaluate(frm, imgHtml, title);
                    }
                    else
                    {
                        alert(turnData.message);
                    }
                  }
            });
      });

    });
  // 更新评测信息
  function updateEvaluate(frm, imgHtml, title) {
      frm.parent().siblings(".evaluate-title").children("input").val(turnData.data.t);
      frm.parent().siblings(".evaluate-img").html(imgHtml);
  }
  function delGearImg(frm)
  {
    if(confirm("确认删除？") == true)
    {
        var gearImgDiv = $(frm).parents(".gearImgDiv");
        var rel = $(gearImgDiv).remove();
    }
  }
  function delEvaluate(frm)
  {
    if(confirm("确认删除？") == true)
    {
        var evaluate = $(frm).parents(".evaluate");
        var rel = $(evaluate).remove();
    }
  }
  // 删除配色
  function delblendent(frm, id)
  {
    if(confirm("确认删除？") == true)
    {
        var blendentDiv = $(frm).parents(".blendent");
        var gearId = $("input[name='gearId']").val();

        if(id > 0 && gearId >0)
        {
          $.ajax({url:"index.php?c=admin&a=delBlendent&id=" + id + "&gearId=" + gearId,
                  async:false,
                  dataType:"json",
                  error:function(){
                      alert('未知错误');
                      },
                  success:function(data, status){
                    var data = eval(data);
                    if(data.rel == true)
                    {
                       $(blendentDiv).remove();
                    }
                    else{
                      alert(data.message);
                    }
                  }
            });
        }
        else
        {
          $(blendentDiv).remove();
        }
    }
  }

</script>
<form class="form-horizontal" id="custom_data" action="index.php?c=admin&a=gearAction" method="post" enctype="multipart/form-data">
  <legend>基本信息</legend>  
  <div class="control-group">
    <label class="control-label" for="inputTiltle">装备名称：</label>
    <div class="controls">
      <input class="input-xxlarge" type="text" name='name' placeholder="请输入装备名称" value="{$gearInfo['name']}">
      建议控制在20个汉字长度之内
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="inputTiltle">品类：</label>
    <div class="controls">
      <select name="catId" class="catId" id="catId" data-value="$gearInfo['catId']">
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label">品牌：</label>
    <div class="controls">
      <select name="brand" class="brand" size="10" data-value="$gearInfo['brand']['brandId']">
      </select>
    </div>
  </div>

    <div class="control-group">
    <label class="control-label">性别：</label>
    <div class="controls">
      <select name="gender" class="input-mini">
        <option value="1" {if $gearInfo['gender'] == 1} selected="selected" {/if}>男</option>
        <option value="2" {if $gearInfo['gender'] == 2} selected="selected" {/if}>女</option>
        <option value="3" {if $gearInfo['gender'] == 3} selected="selected" {/if}>男女通用</option>
      </select>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">建议零售价(人民币)：</label>
    <div class="controls">
      <input type="text" name="price" placeholder="请输入装备价格" value="{$gearInfo['price']}">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">功能简介：</label>
    <div class="controls">
      <textarea name="shortDesc" placeholder="请输入装备简介" rows="5" class="input-xxlarge">$gearInfo['shortDesc']</textarea>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">是否有效：</label>
    <div class="controls">
      <select name="isShow" class="input-mini">
        <option {if $gearInfo['isShow'] == 1} selected="selected" {/if} value="1">是</option>
        <option {if $gearInfo['isShow'] == 0} selected="selected" {/if} value="0">否</option>
      </select>
    </div>
  </div>
   <div class="control-group shopUrlDiv">
    <label class="control-label">识货商品id：</label>
    <div class="controls">
      <input class="input-xxlarge" type="text" name="goods_id" placeholder="识货商品id" value="{$gearInfo['goods_id']}">
    </div>
  </div>

<legend>产品图片</legend> 
  {loop $gearInfo['images'] $k $img}
  <div class="control-group gearImgDiv">
    <label class="control-label" for="inputTiltle">装备照片：</label>
    <div class="controls">
      <div class="control-group">
        <div class="">
          {if $img}
            <img width="50" src="{$img}" alt="装备图片">
            <input type="hidden" name="imgUrl[{$k}]" value="{$img}">
          {/if}
          <input type="file" name="picture_{$k}">
        </div>
      </div>
    </div>
    <div class="controls"><button type="button" class="btn btn-danger" onclick="delGearImg(this)">删除本图</button></div>
  </div>
  {/loop}
  <div class="control-group AddGearImg-div">
    <div class="controls">
        <input type="hidden" value="{$eleLength['imgLength']}" id="MaxGearImg" name="maxImage">
        <button type="button" class="btn btn-primary" id="addGearImg">添加装备图片</button>
    </div>
    建议使用正方形图片，如100*100
  </div>

<legend>测一测关联</legend>
  <div class="control-group" style="display:none">
    <label class="control-label">功能标签：</label>
    <div class="controls">
      <select name="funcTag">
        <option value="">请选择装备功能标签</option>
        {loop $shoeAttr['funcTag'] $k $funcTag}
        <option {if $gearInfo['funcTag'] == $k} selected="selected" {/if} value="{$k}">$funcTag</option>
        {/loop}
      </select>
    </div>
  </div>
    <div class="control-group">
    <label class="control-label">功能：</label>
    <div class="controls">
      <select name="feature">
        <option value="">请选择装备功能</option>
        {loop $shoeAttr['feature'] $k $feature}
        <option {if $gearInfo['feature'] == $k} selected="selected" {/if} value="{$k}">$feature</option>
        {/loop}
      </select>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">层次：</label>
    <div class="controls">
      <select name="level">
        <option value="">请选择装备功层次</option>
        {loop $shoeAttr['level'] $k $level}
        <option {if $gearInfo['level'] == $k} selected="selected" {/if} value="{$k}">$level</option>
        {/loop}
      </select>
    </div>
  </div>
 <div class="control-group">
    <label class="control-label">类别：</label>
    <div class="controls">
      <select name="shoeCat">
        <option value="">请选择装备类型</option>
        {loop $shoeAttr['shoeCat'] $k $shoeCat}
        <option {if $gearInfo['shoeCat'] == $k} selected="selected" {/if} value="{$k}">$shoeCat</option>
        {/loop}
      </select>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">足型：</label>
    <div class="controls">
      {loop $shoeAttr['footType'] $k $footType}
      <label>
        <input class="checkbox" name="footType[]" type="checkbox"{if $fTSelected[$k] == 1} checked="checked" {/if} value="{$k}"> {$footType}
      </label>
      {/loop}
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">适合足类：</label>
    <div class="controls">
      {loop $shoeAttr['footCircle'] $k $footCircle}
      <label>
        <input class="checkbox" name="footCircle[]" type="checkbox"{if $fCSelected[$k] == 1} checked="checked" {/if} value="{$k}"> {$footCircle}
      </label>
      {/loop}
    </div>
  </div>
 
 

  
  <!-- 配色 -->
  <!-- {loop $gearInfo['blendent'] $k $blen} -->
  <div class="control-group blendent" style="display:none">
    <label class="control-label">配色色值：</label>
    <div class="controls">
        <input type="text" id="color0_{$k}" name="color_{$k}[]" disabled="disabled" placeholder="请选择色值" {if $blen['color']}value="{$blen['color'][0]}"{/if} >
        <script>CreateCPBtn('color0_{$k}');</script>
        <br />
        <input type="text" id="color1_{$k}" name="color_{$k}[]" disabled="disabled" placeholder="请选择色值" {if $blen['color']}value="{$blen['color'][1]}"{/if} >
        <script>CreateCPBtn('color1_{$k}');</script>
    </div>
    <label class="control-label">图片：</label>
    <div class="controls">
        {if $blen['img']}
          <img width="50" src="{$blen['img']}" alt="配色图片">
          <input type="hidden" name="blenImg[{$k}]" value="{$blen['img']}">
        {/if}
        <input type="file" name="blendent_{$k}">
    </div>
    <div class="controls">
      <button type="button" class="btn btn-danger" onclick="delblendent(this, {$blen['id']})">删除本配色</button>
    </div>
  </div>
  <!-- {/loop} -->
  <div class="control-group AddBlendent" style="display:none">
    <div class="controls">
        <input type="hidden" value="{$eleLength['blendent']}" id="Maxlendent" name="maxBlendent">
        <button type="button" class="btn btn-primary" id="addBlendent">添加配色</button>
    </div>
  </div>

  <legend style="display:none">电商信息</legend> 
  <div class="control-group shopUrlDiv" style="display:none">
    <label class="control-label">购买链接：</label>
    <div class="controls">
      <input class="input-xxlarge" type="text" name="shopUrl" placeholder="请输入购买链接" value="{$gearInfo['shopUrl']}">
    </div>
  </div>
  

  <legend style="display:none">产品性能</legend> 
  <div class="control-group lightyDiv" style="display:none">
    <label class="control-label">轻量化：</label>
    <div class="controls">
      <input type="text" name="lighty" placeholder="请输入轻量化性能的值" value="{$gearInfo['lighty']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group shocklessenDiv" style="display:none">
    <label class="control-label">避震性：</label>
    <div class="controls">
      <input type="text" name="shocklessen" placeholder="请输入避震性能的值" value="{$gearInfo['shocklessen']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group comfortDiv" style="display:none">
    <label class="control-label">舒适度：</label>
    <div class="controls">
      <input type="text" name="comfort" placeholder="请输入舒适度性能的值" value="{$gearInfo['comfort']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group fiexibilityDiv" style="display:none">
    <label class="control-label">灵活性：</label>
    <div class="controls">
      <input type="text" name="fiexibility" placeholder="请输入灵活性能的值" value="{$gearInfo['fiexibility']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group griplityDiv" style="display:none">
    <label class="control-label">抓地性：</label>
    <div class="controls">
      <input type="text" name="griplity" placeholder="请输入抓地性能的值" value="{$gearInfo['griplity']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group durablilityDiv" style="display:none">
    <label class="control-label">耐久性：</label>
    <div class="controls">
      <input type="text" name="durablility" placeholder="请输入耐久性能的值" value="{$gearInfo['durablility']}">
      <span>0到5之间的整数</span>
    </div>
  </div>
  <div class="control-group sizefeelDiv" style="display:none">
    <label class="control-label">尺码感受：</label>
    <div class="controls">
    <input type="text"  name="sizefeel" id="sizefeel" placeholder="请输入尺码感受的值" value="{$gearInfo['sizefeel']}" />
      &nbsp;<span>0到100之间的整数（偏小——>偏大）50正好</span>

    <!--  <input type="range" min="0" max="100" step="1" name="sizefeel" id="sizefeel" onchange="change()"placeholder="请输入尺码感受的值" />&nbsp;<span id="sizevalue" ></span>
      &nbsp;<span>0到100之间的整数（偏小——>偏大）</span>  -->
    </div>
  </div>
  


  <div style="display:none">

  <div class="control-group">
    <label class="control-label" for="inputauthor">重量(克)：</label>
    <div class="controls">
      <input  type="text" name="weight" placeholder="请输入装备重量" value="{$gearInfo['weight']}">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">上市日期：</label>
    <div class="controls">
    <input type="text" name="publishTime" id="publish_time_id" value="{eval echo date('Y-m', $gearInfo['publishTime'])}">
      <input type="button" id="publish_time_btn" onclick="return showCalendar('publish_time_id', '%Y-%m', '24', false, 'publish_time_btn');" value="选择" class="button" id="publish_time_id"/>
    </div>
  </div>
 
  
  <div class="control-group">
    <label class="control-label">最低价：</label>
    <div class="controls">
      <input type="text" name="minprice" placeholder="请输入装备最低价" value="{$gearInfo['minprice']}">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label">币种：</label>
    <div class="controls">
      <label><input type="radio" name="currency-old" value="0" {if $gearInfo['currency'] == 0}checked="checked"{/if}>人民币</label>
      <label><input type="radio" name="currency-old" value="1" {if $gearInfo['currency'] == 1}checked="checked"{/if}>美元</label>
    </div>
  </div>
  <input type="hidden" name="currency" value="0">
   <div class="control-group scoreDiv">
    <label class="control-label">综合评分：</label>
    <div class="controls">
      <input type="text" name="score" placeholder="请输入综合评分" value="{$gearInfo['score']}">
      <span>0到5之间的数（保留一位小数点）</span>
    </div>
  </div>

  <legend>产品评测</legend> 
  {loop $gearInfo['evaluate'] $k $eval}
  <div class="control-group evaluate">
    <label class="control-label">测评：</label>
    <div class="controls">
      <label class="label-in-control">ID：</label>
      <div class="control-in-controls">
        <input type="text" name="evaluate[]" placeholder="帖子ID" value="{$eval['id']}" id="evaluateid">
      </div>
      <label class="label-in-control">标题：</label>
      <div class="control-in-controls evaluate-title">
        <input type="text" id="evaltitle_$k" disabled="disabled" value="{$eval['title']}">
      </div>
      <label class="label-in-control">图片：</label>
      <div class="control-in-controls evaluate-img">
        {loop $eval['img'] $kk $img}
        <img width="50" src="{$img}">
        {/loop}
      </div>
    </div>
    <div class="controls pad5 pad-left10"><button type="button" class="btn btn-danger" onclick="delEvaluate(this)">删除本评测</button></div>
  </div>
  {/loop}
  <div class="control-group AddEvaluate">
    <div class="controls pad-left10">
        <input type="hidden" name="maxEvaluate" value="{$eleLength['evaluate']}" id="MaxEval">
        <button type="button" class="btn btn-primary " id="addEvaluate">添加测评</button>
    </div>
  </div>
  </div>
  
  <div class="control-group">
    <div class="controls">
        <input type="hidden" name="gearId" value="{$gearInfo['gearId']}">
        <input type="hidden" name="action" value="{$action}">
        <button type="submit" class="btn">提交</button>
    </div>
  </div>
</form>

<script src="/static/js/jquery.cxselect.min.js"></script>
<script>
    $('#custom_data').cxSelect({
  selects: ['catId', 'brand'],
  jsonName: 'name',
  jsonValue: 'value',
  jsonSub: 'sub',
  data:  $rootCatJson
});
</script>

{template footer}